package genetic.q1.functions.sumlist.statements;

import genetic.q1.WithallPhenotype;
import genetic.q1.functions.Program;
import genetic.q1.functions.ProgramObject;
import genetic.q1.functions.Statement;
import genetic.q1.functions.Variable;

public class Assign extends Statement {

	private Assign(ProgramObject[] evals) {
		super("Assign", evals);
	}
	
	
	public Assign() {
		super("Assign", null);
	}


	@Override
	public Statement CreateInstance(ProgramObject[] evals) {
		return new Assign(evals);
	}

	@Override
	public ProgramObject choose(int j, int i, WithallPhenotype withallPhenotype) {
		if (j==0){
			return withallPhenotype.getFromWriteVars(i);
		} else if (j==1){
			return withallPhenotype.getFromReadWriteVars(i);
		}
		return null;
	}

	@Override
	public int execute(Program program) {
		int value = ((Variable)evals[1]).getValue();
		((Variable)evals[0]).setValue(value);
		return program.getCounter() + 1;
	}


	@Override
	public String getObjectName() {
		return "Assign("+evals[0].getObjectName()+","+evals[1].getObjectName()+");";
	}


	@Override
	public int getNumVars() {
		return 2;
	}
	
	@Override
	public String toString() {
		 return evals[0].toString() + " = " + evals[1].toString();
	}

}
